from flask import Flask, request,render_template
import json
from pynput.keyboard import Key, Controller

KEY_VALUE = 'remote_keyboard'

app = Flask(__name__,
            static_folder = "../dist/static",
            template_folder = "../dist")

keyboard = Controller()
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def catch_all(path):
    return render_template("index.html")

@app.route('/api/sendkeys', methods=['POST'])
def sendkeys():
    #print(request.json)
    keys = request.json['keys']
    if keys == 'backspace':        
        keyboard.press(Key.backspace)
    else:
        keyboard.type(keys)
    regResult = {
        'result': 'success'
    }
    return json.dumps(regResult)

app.secret_key = KEY_VALUE
app.run(host='0.0.0.0',debug=True)
